package com.bjx.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bjx.common.core.domain.R;
import com.bjx.common.core.domain.group.Update;
import com.bjx.system.domain.query.PostQuery;
import com.bjx.system.domain.vo.PostVO;
import com.bjx.system.service.IPostService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @desc: 职位控制器
 * @author: liushuai
 * @date: 2022/10/15
 */
@RequestMapping("/post")
@Tag(name = "职位控制器")
@RestController
public class PostController {

    @Autowired
    private IPostService postService;

    /**
     * 分页查询职位列表
     * @param postQuery
     * @return: R<IPage<PostVO>>
     * @Author: liushuai
     * @Date: 2022/10/15
     */
    @Operation(summary = "分页查询职位列表")
    @GetMapping("listPostPage")
    public R<IPage<PostVO>> listPostPage(PostQuery postQuery) {
        IPage<PostVO> page = postService.listPostPage(postQuery);
        return R.success(page);
    }

    /**
     * 查询所有职位
     * @param
     * @return: com.bjx.common.core.domain.R<java.util.List<com.bjx.system.domain.vo.PostVO>>
     * @Author: liushuai
     * @Date: 2022/10/17
     */
    @Operation(summary = "查询所有职位列表")
    @GetMapping("listPostAll")
    public R<List<PostVO>> listPostAll() {
        List<PostVO> list = postService.listPostAll();
        return R.success(list);
    }


    /**
     * 根据职位id查询职位
     * @param postId
     * @return:R<PostVO>
     * @Author: liushuai
     * @Date: 2022/10/15
     */
    @Operation(summary = "根据职位id查询职位")
    @GetMapping("selectPostByPostId")
    public R<PostVO> selectPostByPostId(@RequestParam Long postId){
        PostVO vo = postService.selectPostByPostId(postId);
        return R.success(vo);
    }

    /**
     * 根据职位id删除职位
     * @param postId
     * @return: R
     * @Author: liushuai
     * @Date: 2022/10/15
     */
    @Operation(summary = "根据职位id删除职位")
    @GetMapping("deletePostByPostId")
    public R deletePostByPostId(@RequestParam Long postId){
        postService.deletePostByPostId(postId);
        return R.successMsg("删除职位成功");
    }

   /**
    * 新增职位
    * @param postVO
    * @return: R
    * @Author: liushuai
    * @Date: 2022/10/15
    */
   @Operation(summary = "新增职位")
   @PostMapping("insertPost")
   public R insertPost(@RequestBody @Validated PostVO postVO){
      postService.insertPost(postVO);
      return R.successMsg("新增职位成功");
   }

    /**
     * 修改职位
     * @param postVO
     * @return: R
     * @Author: liushuai
     * @Date: 2022/10/15
     */
    @Operation(summary = "修改职位")
    @PostMapping("updatePost")
    public R updatePost(@RequestBody @Validated(Update.class) PostVO postVO){
        postService.updatePost(postVO);
        return R.successMsg("修改职位成功");
    }
}
